package main

import (
	"fmt"
	"github.com/ngaut/log"
)

type struct1 struct {
	name    string
	struct2 struct {
		clients []struct {
			client string
		}
	}
}
type Proxy struct {
	Address string
	Port    string
}
type Configuration struct {
	Val string
	Proxy
}

func changeStruct1Name(s struct1) {
	s.name = "cshi"
}
func t_nested_struct() {
	var s []int
	log.Info("s=", s, s == nil) //注意打印出的不是nil，是[]，虽说s==nil返回true
	s1 := new(struct1)
	log.Info(s1.struct2.clients)
	log.Info(s1.name == "", s1.struct2, s1.struct2.clients == nil)

	s1.struct2.clients = []struct{ client string }{
		//{},
	}
	log.Info(s1.struct2.clients == nil)
	log.Info(s1.struct2.clients)
	changeStruct1Name(*s1)
	log.Info("s1 name:", s1.name)

	c := &Configuration{
		Val: "test",
		Proxy: Proxy{
			Address: "addr",
			Port:    "port",
		},
	}
	fmt.Println(*c)

	set := func(c *Configuration) {
		c.Val = "in closure"
	}
	set(c)
	fmt.Println("set by closure:" ,c.Val)
}
